package com.gis.servlet.notice;

import com.gis.dao.NoticeDao;
import com.gis.util.Constant;
import com.gis.util.ResponseUtil;
import com.gis.util.RestResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author t-zhaoheng
 * @since 2022/4/19
 */
@WebServlet("/notice/delete.do")
public class DeleteNoticeServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    this.doPost(req, resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    Integer id = Integer.parseInt(req.getParameter("id"));
    int i = NoticeDao.getInstance().deleteNotice(id);
    if (i > 0) {
      ResponseUtil.writeJson(resp, RestResponse.success(Constant.DELETE_SUCCESS));
    } else {
      ResponseUtil.writeJson(resp, RestResponse.fail(Constant.DELETE_FAILED));
    }
  }
}
